package ch09;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class _36_RegularEx2 {
	public static void main(String[] args) {
		String[] data = { "bat", "baby", "bonus", "c", "cA", "ca", "co", 
				"c.", "c0", "c#", "car", "combat", "count", "date", "disc"};
		String[] pattern = { ".*", "c[a-z]*", "c[a-z]", "c[a-zA-Z]",
				"c[a-zA-Z0-9]", "c.", "c.*", "c\\.", "c\\w", "c\\d", "c.*t",
				"[b|c].*", ".*a.*", ".*a.+", "[b|c].{2}"};

		for (int x = 0; x < pattern.length; x++) {
			Pattern p = Pattern.compile(pattern[x]);
			System.out.print(pattern[x] + ": ");
			for (int i = 0; i < data.length; i++) {
				Matcher m = p.matcher(data[i]);
				if (m.matches()) System.out.print(data[i] + " ");
			}
			System.out.println();
		}
	}
}
/*
. Any character (may or may not match line terminators)
X* X, zero or more times 
X+ X, one or more times 
\w A word character: [a-zA-Z_0-9]
\d A digit: [0-9] 
\D A non-digit: [^0-9]   
*/
/*
.*: bat baby bonus c cA ca co c. c0 c# car combat count date disc 
c[a-z]*: c ca co car combat count 
c[a-z]: ca co 
c[a-zA-Z]: cA ca co 
c[a-zA-Z0-9]: cA ca co c0 
c.: cA ca co c. c0 c# 
c.*: c cA ca co c. c0 c# car combat count 
c\.: c. 
c\w: cA ca co c0 
c\d: c0 
c.*t: combat count 
[b|c].*: bat baby bonus c cA ca co c. c0 c# car combat count 
.*a.*: bat baby ca car combat date 
.*a.+: bat baby car combat date 
[b|c].{2}: bat car 
*/